﻿@{
    Layout = "~/Views/Shared/_WxLayout.cshtml";
    ViewBag.Title = "随机练习";
    int min = ViewBag.min;
    int max = ViewBag.max;
}
<div style="padding:1em;">
    <h1>@ViewBag.Title</h1>
    <p>
        按数量随机选择题目进行练习
    </p>
</div>

<div class="weui-cells__title">请设置题目数：<span id="spanNum">10</span></div>
<div style="text-align:center;">
    <a href="javascript:" class="weui-btn weui-btn_mini weui-btn_default" onclick="set(@min);">@min</a>
    <a href="javascript:" class="weui-btn weui-btn_mini weui-btn_warn" onclick="add(-10);">-10</a>
    <a href="javascript:" class="weui-btn weui-btn_mini weui-btn_warn" onclick="add(10);">+10</a>
    <a href="javascript:" class="weui-btn weui-btn_mini weui-btn_default" onclick="set(@max);">@max</a>
</div>
<a href="javascript:" class="weui-btn_cell weui-btn_cell-default" onclick="ok();">确定</a>

<div style="height:4em;">
    <div class="weui-footer weui-footer_fixed-bottom">
        <p class="weui-footer__links">
            <a href="@Url.Action("Index")" class="weui-footer__link">PMP首页</a>
        </p>
        <p class="weui-footer__text">&copy; 2020 jh.sjtu-oec.com</p>
    </div>
</div>

<script>
    function set(num) {
        let min = @min ;
        let max = @max ;
        if (num < min) {
            num = min;
            layer.open({
                time: 2
                , shade: false
                , style: 'background-color: #666;color:#fff; border:none;'
                , content: '最小值为' + min
            });
        }
        if (num > max) {
            num = max;
            layer.open({
                time: 2
                , shade: false
                , style: 'background-color: #666;color:#fff; border:none;'
                , content: '最大值为' + max
            });
        }
        $("#spanNum").text(num);

    }
    function add(num) {
        let n = parseInt($("#spanNum").text()) + num;
        set(n);
    }
    function ok() {
        let obj = new Object();
        obj.number = parseInt($("#spanNum").text());
        let idx = layer.open({
            type: 2
            , shadeClose: false
            , content: '正在生成试卷...'
        });
        $.ajax({
            type: "POST",
            url: "@Url.Action("RandomQuest")",
            data: obj,
            success: function (html) {
                $("body").html(html);
            },
            error: function (err) {
                layer.msg(err.responseText);
            }
        });
    }
</script>
